#include<iostream>
#include<map>

using namespace std;

// <时间,价格>
// <价格,次数>

class StockPrice {
private:
	map<int, int> timeToPrice;//统计时间对应的价格
	map<int, int> priceCount;//统计价格的次数

public:
	StockPrice() {
	}

	void update(int timestamp, int price) {
		if (timeToPrice.count(timestamp)) {
			int oldPrice = timeToPrice[timestamp];
			if (--priceCount[oldPrice] == 0) {
				priceCount.erase(oldPrice);
			}
		}
		timeToPrice[timestamp] = price;
		++priceCount[price];
	}

	int current() {
		return timeToPrice.rbegin()->second;
	}

	int maximum() {
		return priceCount.rbegin()->first;
	}

	int minimum() {
		return priceCount.begin()->first;
	}
};
